//引入请求接口
import {reqCode,reqRegister} from '@/api/'
export default {
    state: () => ({
        code:''
    }),
    mutations:{
        GETCODE(state,data){
            state.code=data
        }
    },
    actions: {
        async getCode({commit},phone){
           const s=  await reqCode(phone)
           if(s.code===200){
                commit("GETCODE",s.data)
                return 'ok'
           }else{
                return Promise.reject(new Error(s.message))
           }
        },
        async register({},{phone,password,code}){
            try{
                const s=await  reqRegister({phone,password,code})
            if(s.code===200){
                    return 'ok'
                }else{
                    return Promise.reject(new Error(s.message))
                }
            }catch(error){
                return Promise.reject(new Error('fail'))
            }
           
        }
    }
}